package com.acme.bankapp.domain.bank;

import java.io.Serializable;

/**
 * Created by zurdan on 14.11.14.
 * E-mail: Zurdanium@gmail.com
 */
public class Client implements Serializable {
    private final Account account;
    private final String name;
    private final Gender gender;

    public Client(final Account account, final String name, final Gender gender) {
        this.account = account;
        this.name = name;
        this.gender = gender;
    }

    public String getSalutation() {
        return gender + " " + name;
    }

    public Account getAccount() {
        return account;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Client)) return false;

        Client client = (Client) o;

        if (account != null ? !account.equals(client.account) : client.account != null) return false;
        if (gender != client.gender) return false;
        if (name != null ? !name.equals(client.name) : client.name != null) return false;

        return true;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder()
                .append(getSalutation())
                .append(":\n")
                .append(account);
        return stringBuilder.toString();
    }

    @Override
    public int hashCode() {
        int result = account != null ? account.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        return result;
    }
}

